<?php
	$title='Fitness forum - view thread';
	$description='Fitness forum view thread';
	$keywords='fitness, muscles, training, supplements, diet, nutririon, forum';
?>
<?php include('fns_db_forum.php'); ?>
<?php include('../views/layouts/_header.php'); ?>
<?php include('../views/layouts/_left.php'); ?>

<style type="text/css">
	body {
	  text-align: center;
	  margin: 0;
	  padding: 0;
	  background-color:white;
	  background:white;
	}
</style>

<?php
$threadID = $_GET['threadID'];
$thread_details = mysqli_fetch_assoc(get_thread($threadID));
$thread_name = $thread_details['subject'];
$result = all_messages_for_thread($threadID);

if ($result == 0)
{
	#echo "Error: " . mysqli_error($cxn);
}
else
{
	echo "<table width=\"100%\"
	class=\"forumline \"cellpadding=\"4\"";
	echo " cellspacing=\"2\" border=\"0\" align=\"center\">";
	echo "<tbody>";
	echo '
	<tr>' .
	'<th colspan="2" style="background:#242424;color: white; font-size: x-large;">'.$thread_name.'</th>
	</tr>';

	logToFile("before for");
	for( $i = 0; $i < mysqli_num_rows( $result ); $i++ )
	{
		$post = mysqli_fetch_assoc( $result );
		echo '<tr>';
		echo '<td valign="middle" class="row" width="1%">';
		echo '<span class="heading3">'. $post['author'] .'</span>';
		echo '</td>';
		echo '<td valign="middle" class="row" width="99%">';
		echo "<span>".$post['date']."</span>";
		echo '</td>';
		echo '</tr>';

		echo "<tr>";
		echo '<td valign="middle" class="post" width="1%">';
		if($post['author'] != 'Unregistered User'){
			$author_details = mysqli_fetch_assoc(get_author_details($post['author']));

			//logToFile(">>> image path: ".$author_details['img_path']);
			if(isset($author_details['img_path']) && $author_details['img_path'] != ""){
				//logToFile(">>> in if");
				printf('<img src="../images/users/thumbnails/%s" style="float:center;" border="2" align="texttop" onclick="window.open(\'/images/users/%s\');"/>', $author_details['img_path'], $author_details['img_path']);
			}

			echo '<br/>Rank: '.$author_details['rank'];
			$num_posts = get_num_posts_for_user($post['author']);
			echo '<br/>Posts: '.$num_posts;
			echo '<br/>Registered on: '.$author_details['create_date'];
			echo '<br/>From: '.$author_details['city'].', '.$author_details['country'];
		}

		echo "</td>";
		echo '<td class="post" valign="middle" width="99%">'.stripslashes($post['body']);
		echo "<br/><span>";
		echo '<a href="post_reply.php?replyTo='.$post['id'].'">Reply</a>';
		if(checkIfAdmin()){
			echo '&nbsp;<a href="delete.php?target=post&id=' .$post['id'] . '">Delete</a>';
		}
		echo "</span>";
		echo '</td>';
		echo "</tr>";

		echo "<tr>";
		echo '<td colspan="2" heigth="5px" style="background:#C1C1B3;">';
		echo "</td>";
		echo "</tr>";
	}
	echo "</tbody></table>";
}
?>

<?php include('../views/layouts/_footer.php'); ?>
